home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
prolog_2.zip
/
PUZZLES.ZIP
/
COUSIN.PRO
< prev
next >
Wrap
Text File
|
1987-05-30
|
4KB
|
112 lines
/* Cousin.PRO to find Nth cousins Mth removed in a family tree */
/**************************************************************
* *
* Programming assignment #2 ----> Using Prolog *
* *
* Name : John Kai-Yui Sun *
* *
* SSNO : 568-85-6292 *
* *
* Subj : CS 380-01 Programming Languages *
* *
* Date : Nov 22, 1986 *
* *
* Inst : Dr. John V. Erhart *
* *
**************************************************************
It is easy to characterize cousins: two people are Nth cousins
Mth removed (M ≥ 0) if and only if the ancestor of one N + 1
generations past is the same as the ancestor of other N + 1 + M
generations past and they have no common ancestors in the past
N generations.
*/
/* Rules */
sibling(Person_X, Person_Y) :-
parent_child(Person_Z, Person_X),
parent_child(Person_Z, Person_Y),
Person_X \= Person_Y.
ancestor(Person_X, Person_Y, 0) :- sibling(Person_X, Person_Y).
ancestor(Person_X, Person_Y, 1) :- parent_child(Person_X, Person_Y).
ancestor(Person_X, Person_Y, N_Levels) :-
N_Levels_minus_1 is N_Levels - 1,
N_Levels_minus_1 > 0,
ancestor(Person_X, Person_Z, N_Levels_minus_1),
parent_child(Person_Z, Person_Y).
is_cousin(X, Y, N) :-
N > 0,
sibling(V, W),
ancestor(W, X, N),
ancestor(V, Y, N).
find_cousin(X, Y, N, 0) :-
is_cousin(X, Y, N).
find_cousin(X, Y, N, 0) :- !.
find_cousin(X, Y, N, M) :-
is_cousin(X, W, N),
ancestor(W, Y, M).
find_cousin(X, Y, N, M) :-
is_cousin(Y, W, N),
ancestor(W, X, M).
/* Facts */
parent_child(charles, tom).
parent_child(charles, mary).
parent_child(charles, max).
parent_child(tom, bill).
parent_child(tom, sue).
parent_child(mary, frankie).
parent_child(mary, marie).
parent_child(max, judy).
parent_child(max, jane).
parent_child(bill, larry).
parent_child(bill, edith).
parent_child(sue, joe).
parent_child(sue, tammy).
parent_child(frankie, cyrus).
parent_child(marie, paul).
parent_child(marie, ida).
parent_child(judy, suzy).
parent_child(judy, sammy).
parent_child(larry, dave).
parent_child(larry, gazina).
parent_child(joe, adam).
parent_child(tammy, vidas).
parent_child(tammy, rosetta).
parent_child(cyrus, lela).
parent_child(paul, irene).
parent_child(suzy, vince).
parent_child(gazina, betty).
parent_child(vidas, jesse).
parent_child(vidas, ruth).
parent_child(rosetta, edward).
parent_child(vince, leroy).
parent_child(vince, alex).
parent_child(betty, barbara).
parent_child(betty, bernice).
parent_child(jesse, james).
parent_child(jesse, annie).
parent_child(edward, shelly).
parent_child(leroy, agnes).
parent_child(barbara, jason).
parent_child(james, frank).
parent_child(annie, fran).
parent_child(annie, ollie).
parent_child(shelly, robert).
parent_child(agnes, tim).
parent_child(agnes, ralph).
parent_child(ralph, paula).